﻿/*
 * @Autor: PK
 * @Date: 2022/01/14 21:49:SS
 */

using System;
using System.Collections.Generic;
using ShkSimulation.core.dao.input.resource;
using ShkSimulation.core.template.agency;
using ShkSimulation.core.util;

namespace ShkSimulation.core.factory {

	public delegate Dictionary<int, Agency> CreateAgenciesFunction(Resource resource, List<CreateParam> createParams);
	
	public class AgencyFactoryByResource: AgencyFactory {
		
		public AgencyFactoryByResource(string resourceKey, CreateAgenciesFunction agencyCreateFunction) {
			this.ResourceKey = resourceKey;
			this.AgencyCreateFunction = agencyCreateFunction;
		}
		
		public string ResourceKey { get; private set; }
		
		private CreateAgenciesFunction AgencyCreateFunction { get; set; }

		public Dictionary<int, Agency> Create(Resource resource) {
			if (AgencyCreateFunction == null) {
				return new Dictionary<int, Agency>();
			}
			List<CreateParam> lines = CollectionUtil.DataTableToCreateParams(resource?.GetDataTable());
			return AgencyCreateFunction(resource, lines);
		}
		

	}

}